package com.heima.thread.safe.deadLock;

public class MyThread extends Thread{


    static Object objA = new Object();
    static Object objB = new Object();

    @Override
    public void run() {
        while(true)
        {
            if(getName().equals("线程A")){
                synchronized (objA){
                    System.out.println("线程A拿到了A锁, 准备去拿B锁");
                    synchronized (objB){
                        System.out.println("线程A拿到了B锁, 顺利执行完了一轮");
                    }
                }
            }else if(getName().equals("线程B")){

                synchronized (objB){
                    System.out.println("线程B拿到了B锁, 准备去拿A锁");
                    synchronized (objA){
                        System.out.println("线程B拿到了A锁, 顺利执行完了一轮");
                    }
                }
            }
        }
    }
}
